﻿using CommonServiceLocator;
using GalaSoft.MvvmLight.Ioc;
using Jn698._45GWTool.Models.DataGrid;
using Jn698._45GWTool.ViewModels;
using Jn698._45GWTool.ViewModels.Controls;
using Jn698._45GWTool.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Jn698._45GWTool.Controls
{
    /// <summary>
    /// AddOrUpdateConnectArControl.xaml 的交互逻辑
    /// </summary>
    public partial class AddOrUpdateConnectPlanControl : UserControl
    {
        public AddOrUpdateConnectPlanControl()
        {
            InitializeComponent();
        }

        private void grd_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var list = ServiceLocator.Current.GetInstance<AddOrUpdateConnectPlanViewModel>().RcsdDataList;
            // 获取所点击的行索引和列索引
            int rowIndex = grd.SelectedIndex;//((selectedCell.Item as DataRowView).Row as DataRow).Table.Rows.IndexOf((selectedCell.Item as DataRowView).Row);//selectedCell.Item as DataRowView == null ? -1 : ((selectedCell.Item as DataRowView).Row as DataRow).Table.Rows.IndexOf((selectedCell.Item as DataRowView).Row);
            int columnIndex = grd.CurrentColumn.DisplayIndex;//selectedCell.Column.DisplayIndex;


            if (columnIndex == 1)
            {
                RCSDDataModel rCSDData = list[rowIndex];
                if (rCSDData.CSD != null && rCSDData.CSD.Equals("记录型对象属性描述符"))
                {
                    SimpleIoc.Default.Unregister<ROADViewModel>();
                    SimpleIoc.Default.Unregister<RCSDDataModel>();
                    GalaSoft.MvvmLight.Ioc.SimpleIoc.Default.Register(() => list[rowIndex]);
                    GalaSoft.MvvmLight.Ioc.SimpleIoc.Default.Register<ROADViewModel>();
                    ROADView rOADView = new ROADView();
                    if (rOADView.ShowDialog() == true)
                    {
                        /*gWCmdMakeUpService.Update(ModeBitViewModel.GWCmdMakeUp);
                        SetDataList[index].DataValue = ModeBitViewModel.GWCmdMakeUp.DataValue;*/
                    }
                }
            }
        }
    }
}
